import { Ui2Wx, Wx2Ui } from '../transform'
import { CLIExample } from '../class'
import { log } from '../util'

export declare namespace TransformCommand {
    interface Options {
        type: string;
        src: string;
        dest: string;
    }
    interface CLIOptions {
    }
}

export class TransformCommand {

    private transformer!: Ui2Wx | Wx2Ui
    constructor(public options: TransformCommand.Options) {
    }

    run() {
        let { type, src, dest } = this.options;
        switch (type) {
            case 'ui2wx': {
                this.transformer = new Ui2Wx(src, dest);
            }
                break;
            case 'wx2ui': {
                this.transformer = new Wx2Ui(src, dest);
            }
                break;
            default:
                log.error('未知的转换类型');
                break;
        }
        return this.transformer?.transform();
    }
}

export default {
    name: 'transform [name]',
    alias: '',
    usage: '[name]',
    description: '转换项目',
    on: {
        '--help': () => {
            new CLIExample('transfrom')
                .group('转换项目')
                .rule('');
        }
    },
    options: [
        ['-t, --type <transform type>', '转换类型，ui2wx 或 wx2ui'],
        ['-i, --src <src path>', '输入路径'],
        ['-o, --dest <dest path>', '输出路径']
    ],
    action(name: string, options: TransformCommand.Options) {
        let transformCommand = new TransformCommand(options);
        return transformCommand.run();
    }
};
